VPATH = source:./source/obj:./source/lib

matf : tree main.c libf.so
	gcc ./source/main.c -L./source/lib -lf -o ./services/matf

libf.so : lib.o
	gcc -shared ./source/obj/libf.o -o ./source/lib/libf.so

lib.o : libf.c
	gcc -c -fPIC ./source/libf.c -o ./source/obj/libf.o

.PHONY : tree debug opt test clean
tree :
	if [ ! -d ./data ]; then mkdir ./data; fi
	if [ ! -d ./data/man ]; then mkdir ./data/man; fi
	if [ ! -d ./data/test ]; then mkdir ./data/test; fi
	if [ ! -d ./interfaces ]; then mkdir ./interfaces; fi
	if [ ! -d ./services ]; then mkdir ./services; fi
	if [ ! -d ./source ]; then mkdir ./source; fi
	if [ ! -d ./source/obj ]; then mkdir ./source/obj; fi
	if [ ! -d ./source/lib ]; then mkdir ./source/lib; fi
	if [ ! -d ./temp ]; then mkdir ./temp; fi

debug : tree main.c libf.so
	gcc ./source/main.c -g2 -L./source/lib -lf -o ./services/matf

opt : tree main.c libf.so
	gcc ./source/main.c -g2 -O -L./source/lib -lf -o ./services/matf

test : tree main.c libf.so
	gcc ./source/main.c -g2 -pg -fprofile-arcs -ftest-coverage -L./source/lib -lf -o ./services/matf
	gcc ./source/power_5.5_3.c -L./source/lib -lf -o ./data/test/power_5.5_3
	gcc ./source/power_-10_5.c -L./source/lib -lf -o ./data/test/power_-10_5
	gcc ./source/factorial_0.c -L./source/lib -lf -o ./data/test/factorial_0
	gcc ./source/factorial_6.c -L./source/lib -lf -o ./data/test/factorial_6
	gcc ./source/modul_-54.34.c -L./source/lib -lf -o ./data/test/modul_-54.34
	gcc ./source/modul_378.c -L./source/lib -lf -o ./data/test/modul_378
	./data/test/power_5.5_3
	./data/test/power_-10_5
	./data/test/factorial_0
	./data/test/factorial_6
	./data/test/modul_-54.34
	./data/test/modul_378

clean :
	rm ./data/test/* ./source/lib/*.so ./source/obj/*.o ./services/* ./temp/* ./*.out ./*.gcda ./*.gcno
